$(function () {
    var $problemFeedbackTableForm = $(".problemFeedback-table-form");
    var settings = {
        url: ctx + "problemFeedback/list",
        pageSize: 10,
        queryParams: function (params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
            };
        },
        columns: [{
            checkbox: true
        }, {
            field: 'id',
            visible: false,
            title: 'Id'
        }, {
            field: 'problemRecord',
            title: '问题记录'
        }, {
            field: 'expectedResults',
            title: '预期结果'
        },
            {
                field: 'enclosureTag',
                title: '附件状态',
                formatter: function (value, row, index) {
                    if (value === '1') return '<span class="badge badge-success">已解决</span>';
                    if (value === '0') return '<span class="badge badge-warning">未解决</span>';
                }
            },
            {
                field: 'enclosure',
                title: '附件',
                formatter: function (value, row, index) {
                    // var a = '< a href="javascript:downloadhrNedput(${'+row.id+'});" >'+value+'</ a>';
                    // return  "<a href='javascript:downloadhrNedput("+row.enclosure+");'>'<span>"+row.enclosure+"</span>'</a>";

                    return "<a href='javascript:;' onclick='downloadhrNedput(" + row.id + ")'>'<span>" + row.enclosure + "</span>'</a>";


                }
            }, {
                field: 'createTime',
                visible: false,
                title: '创建时间'
            },

        ]
    };

    $MB.initTable('problemFeedbackTable', settings);
});

function search() {
    $MB.refreshTable('problemFeedbackTable');
}


function refresh() {
    $(".problemFeedback-table-form")[0].reset();
    search();
}

/* 下载 */
function downloadhrNedput(id) {
    window.location.href = "problemFeedback/downloadFile?id=" + id;
}

function deleteProblemFeedback() {
    var selected = $("#problemFeedbackTable").bootstrapTable('getSelections');
    var selected_length = selected.length;
    if (!selected_length) {
        $MB.n_warning('请勾选需要删除的项目！');
        return;
    }
    var ids = "";
    for (var i = 0; i < selected_length; i++) {
        ids += selected[i].id;
        if (i !== (selected_length - 1)) ids += ",";
    }
    $MB.confirm({
        text: "确定删除选中的项目？",
        confirmButtonText: "确定删除"
    }, function() {
        $.post(ctx + 'problemFeedback/delete', { "ids": ids }, function(r) {
            if (r.code === 0) {
                $MB.n_success(r.msg);
                refresh();
            } else {
                $MB.n_danger(r.msg);
            }
        });
    });
}

